home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Other / mCD / Source / PrefsController.m < prev    next >
Encoding:
Text File  |  1994-06-26  |  7.3 KB  |  290 lines

  1.  
  2. #import "PrefsController.h"
  3. #import "PrefsPanel.h"
  4. #import "scsi_cd.subproj/ListScsi.h"
  5.  
  6. @implementation PrefsController
  7.  
  8. - showPrefsPanel:sender
  9. {
  10.  /*
  11.   * mCD_Prefs.nib is setup with this object as it's owner, so it fills in the
  12.   * ID for prefsPanel 
  13.   */
  14.     if (!prefsPanel)
  15.     [NXApp loadNibSection:"mCD_Prefs.nib" owner:self];
  16.  
  17.  /* ListScsi seems to cause trouble... */
  18.  /* so skip: if ( ! list_SCSI ) list_SCSI = [[ListScsi alloc] init]; */
  19.  
  20.     [prefsPanel showPrefsPanel:self usingScsiList:list_SCSI];
  21.  
  22.     return self;
  23. }
  24.  
  25. #define Def_CDDRIVE "CDDrive"
  26. - _findFirstCdDrive
  27. {
  28.     int                 devIndex;
  29.  
  30.     if (!list_SCSI)
  31.     list_SCSI = [[ListScsi alloc] init];
  32.  
  33.     globRawDeviceName[0] = '\0';
  34.     for (devIndex = 0; devIndex <= 6; devIndex++) {
  35.     if ([list_SCSI getTypeOfDev:devIndex] == DEVTYPE_CDROM) {
  36.         sprintf(globRawDeviceName, "/dev/rsd%dh", devIndex);
  37.         break;
  38.     }
  39.     } /* end for(devIndex =... */
  40.  
  41.     if (globRawDeviceName[0] == '\0') {
  42.     NXRunAlertPanel(0,
  43.       "Can't seem to find CD-ROM drive,\nassuming /dev/rsd1h will work",
  44.             0, 0, 0);
  45.     strcpy(globRawDeviceName, "/dev/rsd1h");
  46.     }
  47.     return self;
  48. }
  49.  
  50. - _dreadRawDeviceName
  51. {
  52.     strcpy(globRawDeviceName, "/dev/rsd1h");
  53.     if (NXGetDefaultValue([NXApp appName], Def_CDDRIVE)) {
  54.     strcpy(globRawDeviceName, NXGetDefaultValue([NXApp appName],
  55.                             Def_CDDRIVE));
  56.     }
  57.     if (!strcmp(globRawDeviceName, "/dev/rsd0h"))
  58.     globRawDevicePrefTag = 0;
  59.     if (!strcmp(globRawDeviceName, "/dev/rsd1h"))
  60.     globRawDevicePrefTag = 1;
  61.     if (!strcmp(globRawDeviceName, "/dev/rsd2h"))
  62.     globRawDevicePrefTag = 2;
  63.     if (!strcmp(globRawDeviceName, "/dev/rsd3h"))
  64.     globRawDevicePrefTag = 3;
  65.     if (!strcmp(globRawDeviceName, "/dev/rsd4h"))
  66.     globRawDevicePrefTag = 4;
  67.     if (!strcmp(globRawDeviceName, "/dev/rsd5h"))
  68.     globRawDevicePrefTag = 5;
  69.     if (!strcmp(globRawDeviceName, "/dev/rsd6h"))
  70.     globRawDevicePrefTag = 6;
  71.  
  72.  /* the more complicated option */
  73.     if (!strcmp(globRawDeviceName, "FirstDriveFound")) {
  74.     globRawDevicePrefTag = USE_FIRST_CDDRIVE_TAG;
  75.     [self _findFirstCdDrive];
  76.     }
  77.     return self;
  78. }
  79.  
  80. - setRawDevicePrefTag:(int)prefTag andSave:(BOOL)dwriteIt
  81. {
  82.     globRawDevicePrefTag = prefTag;
  83.  
  84.     if (globRawDevicePrefTag == USE_FIRST_CDDRIVE_TAG)
  85.     [self _findFirstCdDrive];
  86.     else if ((prefTag >= 0) && (prefTag <= 6))
  87.     sprintf(globRawDeviceName, "/dev/rsd%dh", prefTag);
  88.  
  89.     if (dwriteIt) {
  90.     if (globRawDevicePrefTag == USE_FIRST_CDDRIVE_TAG)
  91.         NXWriteDefault([NXApp appName], Def_CDDRIVE, "FirstDriveFound");
  92.     else
  93.         NXWriteDefault([NXApp appName], Def_CDDRIVE, globRawDeviceName);
  94.     }
  95.     return self;
  96. }
  97.  
  98. - (char *)rawDeviceName
  99. {
  100.     return globRawDeviceName;
  101. }
  102.  
  103. - (int)rawDevicePrefTag
  104. {
  105.     return globRawDevicePrefTag;
  106. }
  107.  
  108. #define Def_SEPVOL "SeparateVolumes"
  109. - _dreadSeparateVolumes
  110. {
  111.     globSeparateVolumes = NO;
  112.     if (NXGetDefaultValue([NXApp appName], Def_SEPVOL)) {
  113.     strcpy(tempStr, NXGetDefaultValue([NXApp appName],
  114.                       Def_SEPVOL));
  115.     if (!strcmp(tempStr, "yes"))
  116.         globSeparateVolumes = YES;
  117.     if (!strcmp(tempStr, "Yes"))
  118.         globSeparateVolumes = YES;
  119.     if (!strcmp(tempStr, "YES"))
  120.         globSeparateVolumes = YES;
  121.     }
  122.     return self;
  123. }
  124.  
  125. - setSeparateVolumes:(BOOL)onOffSetting andSave:(BOOL)dwriteIt
  126. {
  127.     globSeparateVolumes = onOffSetting;
  128.     if (dwriteIt) {
  129.     if (globSeparateVolumes)
  130.         NXWriteDefault([NXApp appName], Def_SEPVOL, "YES");
  131.     else
  132.         NXRemoveDefault([NXApp appName], Def_SEPVOL);
  133.     }
  134.     return self;
  135. }
  136.  
  137. - (BOOL)separateVolumes
  138. {
  139.     return globSeparateVolumes;
  140. }
  141.  
  142. #define Def_CONSDEB "ConsoleDebugMsgs"
  143. - _dreadConsoleDebugMsgs
  144. {
  145.     globConsoleDebugMsgs = NO;
  146.     if (NXGetDefaultValue([NXApp appName], Def_CONSDEB)) {
  147.     strcpy(tempStr, NXGetDefaultValue([NXApp appName],
  148.                       Def_CONSDEB));
  149.     if (!strcmp(tempStr, "yes"))
  150.         globConsoleDebugMsgs = YES;
  151.     if (!strcmp(tempStr, "Yes"))
  152.         globConsoleDebugMsgs = YES;
  153.     if (!strcmp(tempStr, "YES"))
  154.         globConsoleDebugMsgs = YES;
  155.     }
  156.     return self;
  157. }
  158.  
  159. - setConsoleDebugMsgs:(BOOL)onOffSetting andSave:(BOOL)dwriteIt
  160. {
  161.     globConsoleDebugMsgs = onOffSetting;
  162.     if (dwriteIt) {
  163.     if (globSeparateVolumes)
  164.         NXWriteDefault([NXApp appName], Def_CONSDEB, "YES");
  165.     else
  166.         NXRemoveDefault([NXApp appName], Def_CONSDEB);
  167.     }
  168.     return self;
  169. }
  170.  
  171. - (BOOL)consoleDebugMsgs
  172. {
  173.     return globConsoleDebugMsgs;
  174. }
  175.  
  176. #define DefPfx_CONTROLFRAME "ControlFrame"    /* prefix of controlFrameName */
  177. - _dreadControlFrame
  178. {
  179.     if (NXGetDefaultValue([NXApp appName], controlFrameName)) {
  180.     strcpy(tempStr, NXGetDefaultValue([NXApp appName],
  181.                       controlFrameName));
  182.     [mainPanel_ID setFrameFromString:tempStr];
  183.     }
  184.     return self;
  185. }
  186.  
  187. - saveControlFrame:(BOOL)wantSave
  188. {
  189.     if (wantSave) {
  190.     [mainPanel_ID saveFrameToString:&tempStr[0]];
  191.     NXWriteDefault([NXApp appName], controlFrameName, tempStr);
  192.     } else
  193.     NXRemoveDefault([NXApp appName], controlFrameName);
  194.  
  195.     return self;
  196. }
  197.  
  198. #define Def_VOLUMES "Volumes"
  199. #define DEF_VOLUMESETTING 220
  200. - _dreadVolumes
  201. {
  202.     char               *start, *next;
  203.  
  204.     globLeftVolume = DEF_VOLUMESETTING;
  205.     globRightVolume = DEF_VOLUMESETTING;
  206.     if (NXGetDefaultValue([NXApp appName], Def_VOLUMES)) {
  207.     strcpy(tempStr, NXGetDefaultValue([NXApp appName],
  208.                       Def_VOLUMES));
  209.     start = tempStr;
  210.     if (*start == ' ')
  211.         start++;
  212.     globLeftVolume = globRightVolume = strtod(start, &next);
  213.     if (start != next) {
  214.         start = next;
  215.         if (*start == ' ')
  216.         start++;
  217.         if (*start != '\0')
  218.         globRightVolume = strtod(start, &next);
  219.     }
  220.     globLeftVolume = MIN(globLeftVolume, 255);
  221.     globRightVolume = MIN(globRightVolume, 255);
  222.     if (!globSeparateVolumes)
  223.         globLeftVolume = globRightVolume = MIN(globLeftVolume, globRightVolume);
  224.     }
  225.     return self;
  226. }
  227.  
  228. - saveVolumes:(BOOL)wantSave
  229. {
  230.     int                 leftVolume, rightVolume;
  231.  
  232.     if (wantSave) {
  233.     [cdInfo_ID getVolumes:&leftVolume:&rightVolume];
  234.     if (!globSeparateVolumes)
  235.         leftVolume = rightVolume = MIN(leftVolume, rightVolume);
  236.     if (leftVolume == rightVolume)
  237.         sprintf(tempStr, "%d", leftVolume);
  238.     else
  239.         sprintf(tempStr, "%d %d", leftVolume, rightVolume);
  240.     NXWriteDefault([NXApp appName], Def_VOLUMES, tempStr);
  241.     } else
  242.     NXRemoveDefault([NXApp appName], Def_VOLUMES);
  243.  
  244.     return self;
  245. }
  246.  
  247. - getVolumes:(int *)leftVolPtr :(int *)rightVolPtr
  248. {
  249.     *leftVolPtr = globLeftVolume;
  250.     *rightVolPtr = globRightVolume;
  251.     return self;
  252. }
  253.  
  254. /* this has to be the last action defined, as it references
  255.    many methods which are defined internal to this module */
  256. - initGlobalPreferences:cdInfo mainPanel:ctrlPanel
  257. {
  258.     NXDefaultsVector    defs =
  259.     {
  260.      {DefPfx_CONTROLFRAME, NULL},    /* must be 0-th element */
  261.      {Def_CDDRIVE, NULL},    /* should key on hostname */
  262.      {Def_SEPVOL, NULL},
  263.      {Def_CONSDEB, NULL},
  264.      {Def_VOLUMES, NULL},    /* should key on cd-rom model */
  265.      {NULL, NULL}
  266.     };
  267.  
  268.     cdInfo_ID = cdInfo;
  269.     mainPanel_ID = ctrlPanel;
  270.  
  271.  /* build some defaults names based on current machine/config */
  272.     [NXApp getScreenSize:&mainScreenSize];
  273.     sprintf(controlFrameName, "%s-%1.0fx%1.0f", DefPfx_CONTROLFRAME,
  274.         mainScreenSize.width, mainScreenSize.height);
  275.     defs[0].name = controlFrameName;    /* replace 0-th element */
  276.  
  277.     NXRegisterDefaults([NXApp appName], defs);
  278.  
  279.     [self _dreadRawDeviceName];
  280.     [self _dreadSeparateVolumes];    /* must do before _dreadVolumes */
  281.     [self _dreadConsoleDebugMsgs];
  282.     [self _dreadControlFrame];    /* sets location of cntrlPanel */
  283.     [self _dreadVolumes];
  284.  
  285.     return self;
  286. }
  287.  
  288.  
  289. @end
  290.